const book = require('../data/book.js');

module.exports = {
    //获取书籍列表
    booklist(req, res, next) {
        var booklist = book;
        var query = req.body;
        if(query.name){
            booklist = booklist.filter(item => item.name === query.name);
        }
        if(query.author){
            booklist = booklist.filter(item => item.author === query.author);
        }
        res.json({
            success: true,
            msg: booklist
        });
    },
    //获取书籍详情
    bookdetail(req, res) {
        var booklist = book;
        var id = Number(req.body.id);
        res.json({
            success: true,
            book: booklist.filter(item => item.id === id)[0]
        });
    }
}